<template>
  <view style="padding-bottom: 50px;">
    <my-address></my-address>
    <!-- 标题区域 -->
    <view class="title-box">
      <view style="display: flex;">
        <uni-icons type="shop" size="18"></uni-icons>
        <view class="cart-title">购物车</view>
      </view>
      <view>已选({{getcheckednum}}) / 全部({{total}})</view>
    </view>
    <!-- 商品区域 -->
    <view class="emptyimg" v-if="cart.length==0">
      <image src="../../static/gouwuche.jpg" mode="widthFix"></image>
    </view>
    <uni-swipe-action>
      <block v-for="(goods,i) in cart" :key="i">
        <uni-swipe-action-item :right-options="options" @click="swpierItemHandler(goods)">
          <my-goods :goods="goods" :showRadio="true" :showcount="true" @radio-change="radioChangeHandler"></my-goods>
        </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
    <!-- 结算区域 -->
    <view class="settle-box" v-if="cart.length">
      <my-settle></my-settle>
    </view>
  </view>
</template>

<script>
  import badgeMix from '@/mixin/tabbar-badge.js'
  import {
    mapState,
    mapGetters,
    mapMutations
  } from "vuex"
  export default {
    mixins: [badgeMix],
    computed: {
      ...mapState("m_cart", ['cart']),
      ...mapGetters('m_cart', ['getcheckednum', 'total'])
    },
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#c00000'
          },
        }]
      }
    },
    methods: {
      ...mapMutations("m_cart", ['updateGoodsState', 'delectGoods']),
      radioChangeHandler(e) {
        this.updateGoodsState(e)
      },
      swpierItemHandler(goods) {
        this.delectGoods(goods)
        this.setBadge()
      }
    }
  }
</script>

<style lang="scss">
  .settle-box {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 50px;
    background-color: #fff;
  }

  .emptyimg {
    display: flex;
    justify-content: center;
    margin-top: 160rpx;
  }

  .title-box {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #efefef;
    background-color: #fff;
    padding: 0 10rpx;
    align-items: center;
    .cart-title {
      font-size: 14px;
      margin-left: 4rpx;
    }

  }
</style>
